<template>
	<view>
		<image class="logo ww100" src="@/static/image/fashi.jpg" mode="aspectFill"></image>
		<view class="content p20">
			<view class="item mb40">
				<view class="f32">联系人姓名:</view>
				<input class="mt20" type="text" v-model="name" placeholder="请输入姓名" />
			</view>
			<view class="item mb40">
				<view class="f32">输入联系电话:</view>
				<input class="mt20" type="tel" :maxlength="11" v-model="phone" placeholder="请输入联系电话" />
			</view>
			<view class="item mb40">
				<view class="f32">法事内容:</view>
				<picker class="mt20" mode="selector" :value="active" :range="list" @change="setAct('active', $event)">
					<view class="d-b-c pickerView">
						<view class="" v-if="active >= 0">{{ list[active] }}</view>
						<view class="gray9" v-else>请选择法事内容</view>
						<u-icon name="arrow-down" color="#333" size="15"></u-icon>
					</view>
				</picker>
			</view>
			<view class="item mb40">
				<view class="f32">法事人数:</view>
				<picker class="mt20" mode="selector" :value="mIndex" :range="numList"
					@change="setAct('mIndex', $event)">
					<view class="d-b-c pickerView">
						<view class="" v-if="mIndex >= 0">{{ numList[mIndex] }}</view>
						<view class="gray9" v-else>请选择法事人数</view>
						<u-icon name="arrow-down" color="#333" size="15"></u-icon>
					</view>
				</picker>
			</view>
			<view class="item mb40">
				<view class="f32">备注:</view>
				<input class="mt20" v-model="note" type="text" placeholder="留言内容" />
			</view>
			<u-button text="提交预约" shape="circle" color="#DA2424" :throttleTime="1000" @click="send"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				active: -1,
				numList: [],
				mIndex: -1,
				name: "",
				phone: "",
				note: "",
			};
		},
		onLoad() {
			this.setInit()
		},
		methods: {
			setInit() {
				const init = uni.getStorageSync('init')
				const fashi = JSON.parse(init.fashi)
				const num = JSON.parse(init.num)
				this.list = Object.keys(fashi).map(key => fashi[key]);
				this.numList = Object.keys(num).map(key => num[key]);
			},
			setAct(name, e) {
				this[name] = e.detail.value;
				console.log(this[name]);
			},
			async send() {
				if (this.name == "") return this.$showToast("请输入姓名");
				if (this.phone == "") return this.$showToast("输入联系电话");
				if (this.active == -1) return this.$showToast("请选择法事内容");
				if (this.numList == -1) return this.$showToast("请选择法事人数");
				if (this.note == "") return this.$showToast("请输入备注");
				const res = await this.$request({
					url: this.$api.send,
					data: {
						name: this.name,
						tel: this.phone,
						notes: this.note,
						content: this.list[this.active],
						num: this.numList[this.mIndex],
					},
				});
				uni.showToast({
					icon: "none",
					title: res.msg,
				});
				if (res.code == 1) {
					setTimeout(() => uni.navigateBack(), 1000);
				}
			},
		},
	};
</script>

<style scoped lang="scss">
	.logo {
		height: 400rpx;
	}

	.item {

		input,
		picker {
			background-color: #f7f7f7;
			height: 80rpx;
			padding: 0 40rpx;
			box-sizing: border-box;

			.pickerView {
				height: 80rpx;
			}
		}
	}
</style>